package com.momo.webmagic.util;

import com.momo.webmagic.pojo.JobInfo;
import com.momo.webmagic.service.JobInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import us.codecraft.webmagic.ResultItems;
import us.codecraft.webmagic.Task;
import us.codecraft.webmagic.pipeline.Pipeline;

/**
 * @author ：朱博
 * @description：TODO
 * @date ：2020/12/21 9:05
 */
@Component
public class MyPipeline implements Pipeline {


    @Autowired
    JobInfoService jobInfoService;

    @Override
    public void process(ResultItems resultItems, Task task) {

        //获取封装好的 对象
        JobInfo jobInfo = resultItems.get("jobInfo");

        //判断是否为空
        if(jobInfo != null){
            //如果不为空 存储到数据库中
            this.jobInfoService.save(jobInfo);
        }
    }
}
